/*********************************************************************************/
/*                                                                               */
/*      ICU Driver                                                               */
/*                                                                               */
/*      Last updated by:   CBS                                                   */
/*      Last update date:  2013/3/1                                              */
/*      Revision:          0                                                     */
/*      Copyright:         DENSO                                                 */
/*                                                                               */
/*********************************************************************************/

#ifndef ICU_H
#define ICU_H

/*********************************************************************************/
/*  include files                                                                */
/*********************************************************************************/
#include "Icu_Cfg.h"
#include "Std_Types.h"

/*********************************************************************************/
/*  defines / data types / structs / unions / macros                             */
/*********************************************************************************/
#define ICU_VENDOR_ID        (U2)1
#define MODULE_ID_ICU        (U2)122
#define ICU_INSTANCE_ID      (U1)0

#define ICU_SW_MAJOR_VERSION (U1)1
#define ICU_SW_MINOR_VERSION (U1)0
#define ICU_SW_PATCH_VERSION (U1)0

#define ICU_AR_MAJOR_VERSION (U1)1
#define ICU_AR_MINOR_VERSION (U1)0
#define ICU_AR_PATCH_VERSION (U1)0

/* Service ID */
#define ICU_INIT_SERVICE_ID                    0x00
#define ICU_STARTSIGNALMEASUREMENT_SERVICE_ID  0x13
#define ICU_STOPSIGNALMEASUREMENT_SERVICE_ID   0x14
#define ICU_GETTIMEELAPSED_SERVICE_ID          0x10
#define ICU_GETDUTYCYCLEVALUES_SERVICE_ID      0x11
#define ICU_GETVERSIONINFO_SERVICE_ID          0x12

/* Error Codes */
#define ICU_E_PARAM_CONFIG           0x0A
#define ICU_E_PARAM_CHANNEL          0x0B
#define ICU_E_PARAM_ACTIVATION       0x0C
#define ICU_E_PARAM_BUFFER_PTR       0x0D
#define ICU_E_PARAM_BUFFER_SIZE      0x0E
#define ICU_E_PARAM_MODE             0x0F
#define ICU_E_UNINIT                 0x14
#define ICU_E_NOT_STARTED            0x15
#define ICU_E_BUSY_OPERATION         0x16
#define ICU_E_ALREADY_INITIALIZED    0x17
#define ICU_E_PARAM_NOTIFY_INTERVAL  0x18
#define ICU_E_PARAM_VINFO            0x19

typedef U4 Icu_ValueType;

typedef U1 Icu_HwChannelNumber;

typedef enum
{
    ICU_CH0 = (U1)0,
    ICU_CH1 = (U1)1,
    ICU_CH2 = (U1)2,
    ICU_CH3 = (U1)3,
    ICU_CH4 = (U1)4,
    ICU_CH5 = (U1)5,
    ICU_CH6 = (U1)6,
    ICU_CH7 = (U1)7,
    ICU_CH8 = (U1)8,
    ICU_CH9 = (U1)9,
    ICU_CH10 = (U1)10,
    ICU_CH11 = (U1)11,
    ICU_CH12 = (U1)12,
    ICU_CH13 = (U1)13,
    ICU_CH14 = (U1)14,
    ICU_CH15 = (U1)15,
    ICU_CH16 = (U1)16,
    ICU_CH17 = (U1)17,
    ICU_CH18 = (U1)18,
    ICU_CH19 = (U1)19,
    ICU_CH20 = (U1)20,
    ICU_CH21 = (U1)21,
    ICU_CH22 = (U1)22,
    ICU_CH23 = (U1)23,
    ICU_CH24 = (U1)24,
    ICU_CH25 = (U1)25,
    ICU_CH26 = (U1)26,
    ICU_CH27 = (U1)27,
    ICU_CH28 = (U1)28,
    ICU_CH29 = (U1)29,
    ICU_CH30 = (U1)30,
    ICU_CH31 = (U1)31,
    ICU_NBR_OF_CHANNELS = (U1)32
}Icu_ChannelType;

typedef struct
{
    Icu_ValueType ActiveTime;
    Icu_ValueType PeriodTime;
}Icu_DutyCycleType;

typedef enum
{
    ICU_BOTH_EDGES,
    ICU_FALLING_EDGE,
    ICU_RISING_EDGE
}Icu_ActivationType;

typedef enum
{
    ICU_MODE_EDGE_COUNTER,
    ICU_MODE_SIGNAL_EDGE_DETECT,
    ICU_MODE_SIGNAL_MEASUREMENT,
    ICU_MODE_TIMESTAMP
}Icu_MeasurementModeType;  /* ICU223_Conf */

typedef enum
{
    ICU_ACTIVE_TIME,
    ICU_DUTY_CYCLE,
    ICU_HIGH_TIME,
    ICU_LOW_TIME,
    ICU_PERIOD_TIME
}Icu_SignalMeasurementPropertyType;  /* ICU227_Conf */

typedef struct
{
    Icu_HwChannelNumber IcuHwChannelNumber;
    U1 IcuChannelPrescalerBits;
    U1 IcuInterruptPriority;
    Icu_ActivationType IcuDefaultStartEdge;
    Icu_MeasurementModeType IcuMeasurementMode;
    Icu_SignalMeasurementPropertyType IcuSignalMeasurementProperty;
}Icu_ChannelConfigType;

typedef struct
{
    const U1 NbrOfChannels;
    const U1 GlobalPrescalerBits;
    const Icu_ChannelConfigType* IcuChannelConfig;
}Icu_ConfigType;

/*********************************************************************************/
/*  API Functions                                                                */
/*********************************************************************************/

/***************************************************************************************************/
/*  Service name    :   Icu_Init                                                                   */
/*  Sync/Async      :   Synchronous                                                                */
/*  Reentrancy      :   Non Reentrant                                                              */
/*  Parameters (in) :   Pointer to ICU driver configuration.                                       */
/*  Return value    :   None                                                                       */
/*  Discription     :   This function initializes the driver.                                      */
/***************************************************************************************************/
void Icu_Init(const Icu_ConfigType* ConfigPtr);

/***************************************************************************************************/
/*  Service name    :   Icu_DeInit                                                                 */
/*  Sync/Async      :   Synchronous                                                                */
/*  Reentrancy      :   Non Reentrant                                                              */
/*  Parameters (in) :   None                                                                       */
/*  Return value    :   None                                                                       */
/*  Discription     :   This function de-initializes the ICU module.                               */
/***************************************************************************************************/
#if(ICU_DE_INIT_API == STD_ON)  /* ICU092 ICU301 */
void Icu_DeInit(void);
#endif  /* ICU_DE_INIT_API */

/***************************************************************************************************/
/*  Service name    :   Icu_StartSignalMeasurement                                                 */
/*  Sync/Async      :   Asynchronous                                                               */
/*  Reentrancy      :   Reentrant                                                                  */
/*  Parameters (in) :   Channel  Numeric identifier of the ICU channel.                            */
/*  Return value    :   None                                                                       */
/*  Discription     :   This function starts the measurement of signals.                           */
/***************************************************************************************************/
#if(ICU_SIGNAL_MEASUREMENT_API == STD_ON)  /* ICU142 ICU335 */
void Icu_StartSignalMeasurement(Icu_ChannelType Channel);
#endif  /* ICU_SIGNAL_MEASUREMENT_API */

/***************************************************************************************************/
/*  Service name    :   Icu_StopSignalMeasurement                                                  */
/*  Sync/Async      :   Synchronous                                                                */
/*  Reentrancy      :   Reentrant                                                                  */
/*  Parameters (in) :   Channel  Numeric identifier of the ICU channel.                            */
/*  Return value    :   None                                                                       */
/*  Discription     :   This function stops the measurement of signals of the given channel.       */
/***************************************************************************************************/
#if(ICU_SIGNAL_MEASUREMENT_API == STD_ON)  /* ICU145 ICU337 */
void Icu_StopSignalMeasurement(Icu_ChannelType Channel);
#endif  /* ICU_SIGNAL_MEASUREMENT_API */

/***************************************************************************************************/
/*  Service name    :   Icu_GetTimeElapsed                                                         */
/*  Sync/Async      :   Synchronous                                                                */
/*  Reentrancy      :   Reentrant                                                                  */
/*  Parameters (in) :   Channel  Numeric identifier of the ICU channel.                            */
/*  Return value    :   Icu_ValueType                                                              */
/*  Discription     :   This function reads the elapsed Signal Low Time for the given channel.     */
/***************************************************************************************************/
#if(ICU_GET_TIME_ELAPSED_API == STD_ON)  /* ICU105 ICU341 */
Icu_ValueType Icu_GetTimeElapsed(Icu_ChannelType Channel);
#endif  /* ICU_GET_TIME_ELAPSED_API */

/***************************************************************************************************************************/
/*  Service name    :   Icu_GetDutyCycleValues                                                                             */
/*  Sync/Async      :   Synchronous                                                                                        */
/*  Reentrancy      :   Reentrant                                                                                          */
/*  Parameters (in) :   Channel  Numeric identifier of the ICU channel.                                                    */
/*  Parameters (out):   DutyCycleValue Pointer to a buffer where the results (high time and period time) shall be placed.  */
/*  Return value    :   None                                                                                               */
/*  Discription     :   This function reads the elapsed Signal Low Time for the given channel.                             */
/***************************************************************************************************************************/
#if(ICU_GET_DUTY_CYCLE_VALUES_API == STD_ON)  /* ICU106 ICU345 */
void Icu_GetDutyCycleValues(Icu_ChannelType Channel,Icu_DutyCycleType* DutyCycleValues);
#endif  /* ICU_GET_DUTY_CYCLE_VALUES_API */

/*********************************************************************************************************/
/*  Service name    :   Icu_GetVersionInfo                                                               */
/*  Sync/Async      :   Synchronous                                                                      */
/*  Reentrancy      :   Reentrant                                                                        */
/*  Parameters (out):   versioninfo   Pointer to where to store the version information of this module.  */
/*  Return value    :   None                                                                             */
/*  Discription     :   Return the version information of this module.                                   */
/*********************************************************************************************************/
#if(ICU_GET_VERSION_INFO_API == STD_ON)  /* ICU094 ICU347 */
void Icu_GetVersionInfo(Std_VersionInfoType* versioninfo);
#endif  /* ICU_GET_VERSION_INFO_API */

#endif  /* ICU_H */
/**** End Of File ****************************************************************/